package com.atguigu.redis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class JedisTest {

   static   JedisPool jedisPool = initPool();


   public static JedisPool initPool(){
       JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
       jedisPoolConfig.setMaxTotal(20);
       jedisPoolConfig.setBlockWhenExhausted(true);
       jedisPoolConfig.setMaxWaitMillis(2000);
       jedisPoolConfig.setMinIdle(10);

       jedisPoolConfig.setTestOnBorrow(true);
       jedisPoolConfig.setTestWhileIdle(true);
       jedisPoolConfig.setTestOnReturn(false);


       return new JedisPool(jedisPoolConfig,"hadoop102",6379);

	}


    public static void main(String[] args) {

       // Jedis jedis = new Jedis("hadoop102", 6379);
        Jedis jedis = jedisPool.getResource();
        //如果有密码
        // jedis.auth("123");

        System.out.println("jedis.ping() = " + jedis.ping());

        jedis.set("k100", "v100");
        System.out.println(jedis.get("k100"));

        jedis.close();

    }


}
